package com.my.dubbo.consumer.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;

/**
 * 注解配置类
 */
@Configuration
@EnableDubbo(scanBasePackages = "com.my.dubbo.consumer.annotation")
@ComponentScan(value = {"com.my.dubbo.consumer.annotation"})
public class ConsumerConfiguration {
    @Bean // 应用配置
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("dubbo-annotation-consumer");
//        Map<String, String> stringStringMap = new HashMap<String, String>();
//        stringStringMap.put("qos.enable","true");
//        stringStringMap.put("qos.accept.foreign.ip","false");
//        stringStringMap.put("qos.port","33333");
//        applicationConfig.setParameters(stringStringMap);
        applicationConfig.setQosAcceptForeignIp(false);
        applicationConfig.setQosEnable(true);
        applicationConfig.setQosPort(33333);
        return applicationConfig;
    }

    @Bean // 服务消费者配置
    public ConsumerConfig consumerConfig() {
        ConsumerConfig consumerConfig = new ConsumerConfig();
        consumerConfig.setTimeout(3000);
        return consumerConfig;
    }

    @Bean // 配置注册中心
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setProtocol("zookeeper");
        registryConfig.setAddress("10.25.174.21");
        registryConfig.setPort(2181);
        return registryConfig;
    }
}
